class Solution {
    static reverseList(head) {
        if (head === null) {
            return null
        }

        let pre = null
        let cur = head
        while(cur != null) {
            let next = cur.next
            cur.next = pre
            pre = cur
            cur = next
        }
        return pre
    }

    static reverseListByRecursion(head) {
        if (head === null || head.next === null) {
            return head
        }

        let rev = Solution.reverseListByRecursion(head.next)
        head.next.next = head
        head.next = null
        return rev
    }
}

export {Solution}